package Day2025_03_28;

import java.util.Scanner;

public class Demo02 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] arr = new int[n + 1];
        for (int i = 1; i <= n; i++) arr[i] = in.nextInt();
        int[][] dp = new int[n + 1][2];
        dp[0][0] = Integer.MIN_VALUE;
        int ret = 0;
        for (int i = 1; i <= n; i++) {
            dp[i][0] = Math.max(dp[i - 1][0], dp[i - 1][1] - arr[i]);
            dp[i][1] = Math.max(dp[i - 1][0] + arr[i], dp[i - 1][1]);
            ret = Math.max(ret, dp[i][1]);
        }
        System.out.println(ret);
    }
}
